package com.hupu.jrs.widget.state

import android.view.View
import android.view.animation.Animation

/**
 * Created by sll on 2015/3/13.
 */
abstract class AbstractShowState : ShowState {
    protected lateinit var mFragmentView: View
    protected lateinit var mAnimationIn: Animation
    protected lateinit var mAnimationOut: Animation

    protected fun showViewById(viewId: Int, animate: Boolean) {
        val content = mFragmentView.findViewById<View>(viewId)
        if (animate) {
            mAnimationIn.reset()
            content.startAnimation(mAnimationIn)
        } else {
            content.clearAnimation()
        }
        content.visibility = View.VISIBLE
    }

    protected fun dismissViewById(viewId: Int, animate: Boolean) {
        val content = mFragmentView.findViewById<View>(viewId)
        if (animate) {
            mAnimationOut.reset()
            content.startAnimation(mAnimationOut)
        } else {
            content.clearAnimation()
        }
        content.visibility = View.GONE
    }

    override fun setFragmentView(fragmentView: View) {
        mFragmentView = fragmentView
    }

    override fun setAnimIn(`in`: Animation) {
        mAnimationIn = `in`
    }

    override fun setAnimOut(out: Animation) {
        mAnimationOut = out
    }
}
